package com.neusoft.neuiotms.micro.cmdb;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;

import com.alibaba.fastjson.JSONObject;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;

public interface CmdbMicroService {

    /**
     * @description: 更新实例单个属性更新
     * @param id
     * @param attr
     * @return
     */
    @PutMapping(value = "/instances/{id}/{attr}", consumes = "application/json")
    ResultDTO<JSONObject> updateAttr(@PathVariable String id, @PathVariable String attr, String dto);

    /**
     * @description 更新实例。属性按照{key1冒号value1,
     *              key2冒号value2,...}的形式提交。属性更新是全量更新，否则已存在的属性值会被抹掉，慎用。
     * @param id
     * @return
     */
    @PutMapping(value = "/instances/{id}", consumes = "application/json")
    ResultDTO<JSONObject> update(@PathVariable String id, String dto);

    /**
     * @description 删除关联关系
     * @param id 实例ID或编码
     * @param rid 关联关系实例ID
     * @return
     */
    @DeleteMapping(value = "/instances/{id}/relations/{rid}")
    ResultDTO<JSONObject> deleteRelation(@PathVariable String id, @PathVariable String rid);

    /**
     * @description 查询示例关系
     * @param id
     * @return
     */
    @GetMapping(value = "/instances/{id}/relations")
    ResultDTO<JSONObject> getRelation(@PathVariable String id);

    /**
     * @description 新增关系实例，attrs参数以对象结构提交
     * @param id 模型实例ID
     * @param dto
     * @return
     */
    @PutMapping(value = "/instances/{id}/relations/add", consumes = "application/json")
    ResultDTO<JSONObject> addRelation(@PathVariable String id, String dto);

    /**
     * @description 更新关联关系实例。目前只允许更新desc和属性值。关联关系、源实例、目标实例不允许更新
     * @param id 关系实例ID
     * @param dto
     * @return
     */
    @PutMapping(value = "/relationinstances/{id}", consumes = "application/json")
    ResultDTO<JSONObject> updateRelation(@PathVariable String id, String dto);

    /**
     * @description 根据编码、名字、属性值模糊查询。支持根据属性key:value精确查询s_foo=bar
     * @param schemadef
     * @return
     */
    @GetMapping(value = "/instances/schema/{schemadef}")
    ResultListDTO<JSONObject> getInstanceSchemaBySchemadef(@PathVariable String schemadef);

    /**
     * @description 构造特定属性的树形结构数据。如，位置树是根据位置模型实例的parent属性构造。API层缓存1分钟
     * @return
     */
    @GetMapping(value = "/instances/schema/{schemadef}/tree/by/{attr}")
    ResultListDTO<JSONObject> getInstanceTree(@PathVariable String schemadef, @PathVariable String attr);

    /**
     * @description 实例详情
     * @param id
     * @return
     */
    @GetMapping(value = "instances/{id}")
    ResultDTO<JSONObject> getInstanceById(@PathVariable String id);

    /**
     * @description 批量更新实例属性值
     * @param id 实例ID
     * @param attrs 属性值集合
     * @return
     */
    @PutMapping(value = "/instances/{id}/attrs", consumes = "application/json")
    ResultDTO<JSONObject> updateInstancesAttrs(@PathVariable String id, Object attrs);

    /**
     * @description 创建实例
     * @param instances 实例信息
     * @return
     */
    @PostMapping(value = "/instances", consumes = "application/json")
    ResultDTO<JSONObject> createInstances(String instances);

    /**
     * @description 更新实例
     * @param instances 实例信息
     * @return
     */
    @PutMapping(value = "/instances", consumes = "application/json")
    ResultDTO<JSONObject> updateInstances(String instances);

    /**
     * @description 模型详情
     * @param id
     * @return
     */
    @GetMapping(value = "schemas/{id}")
    ResultDTO<JSONObject> getSchemasById(@PathVariable String id);

    /**
     * @description 模型详情
     * @param id
     * @return
     */
    @GetMapping(value = "bizs/{id}")
    ResultDTO<JSONObject> getBussinessInstanceById(@PathVariable String id);
}
